I can't work out what this error means?!

12 views
Skip to first unread message

Andrew Gill

unread,
May 7, 2025, 2:43:41 PMMay 7
to MiniZinc
Again, big apologies if this is obvious, but I get the following error:

Error: type error: type error in operator application for `'-''. No matching operator found with left-hand side type `set of int' and right-hand side type `int'

The relevant snippets of code are (and I've indicated the line the error refers to):

int: k=4;
array[1..k] of var int: n;
array[2..k] of var int: n_inv;
array[2..k] of var int: p;
array[2..k] of var int: p_inv;
var int: y;
var int: N;

constraint p[2]=n[2];
constraint forall([p[j]=(p[j-1]*n[j]) mod N | j=3..k]); % it complains about this line
constraint p[k]*p_inv[k]+N*y=1;
constraint p_inv[k]>=1;
constraint p_inv[k]<=N-1;
constraint forall([n_inv[j]=(p_inv[j]*p[j-1]) mod N | j=k..3]);
constraint forall([p_inv[j-1]=(p_inv[j]*n[j]) mod N | j=k..3]);
constraint n_inv[2]=p_inv[2];

Any suggestions gratefully accepted :-)

Thanks

Andrew

jason.nguyen

unread,
May 7, 2025, 3:04:48 PMMay 7
to MiniZinc
Hi,

I think the problem is the j=k..3 parts of the comprehensions - this is probably supposed to be j in k..3 (the equals sign in that position is used to give a name to an expression for convenience, the 'in' keyword is used for actual iteration).

Regards,
Jason

Andrew Gill

unread,
May 7, 2025, 3:14:30 PMMay 7
to MiniZinc
OMG - Thanks Jason. I'm using nano on a Linux machine and havent bothered to learn how to cut-and-paste and (thought I) was copying a (correct) previous constraint format. So I have changed the = to in. 

But you reminded me of my second question: is it ok to use j in k..3 or does the range need to be increasing? If the latter, then I can fix it in the indexing.

Thanks again.

Andrew

Cyderize

unread,
May 7, 2025, 3:17:30 PMMay 7
to MiniZinc
The range does indeed need to be increasing, otherwise it evaluates to be the empty set (i.e. 4..3 = {} and not {3, 4}).

Regards,
Jason
Reply all
Reply to author
Forward
0 new messages